<script>
import { unique } from '@/utils/string'

export default {
  name: 'UiChartYaxis',
  inject: {
    UiChart: {
      from: 'UiChart'
    },
    UiChartYaxisGroup: {
      default: null
    }
  },
  props: {
    show: {
      type: Boolean,
      default: true
    },
    /**
     * 纬度数据
    */
    data: {
      type: Array
    },
    name: {
      type: String
    },
    min: {
      type: Number
    },
    max: {
      type: Number
    },
    interval: {
      type: Number
    }
  },
  computed: {
    options() {
      return {
        id: unique(),
        name: this.name,
        min: this.min,
        max: this.max,
        interval: this.interval,
        show: this.show,
        type: this.data ? 'category' : 'value',
        data: this.data
      }
    }
  },
  created() {
    if (this.UiChartYaxisGroup) {
      this.UiChartYaxisGroup.addYaxis(this.options)
    } else {
      this.UiChart.setOption('yAxis', this.options)
    }
  },
  render() {
    return null
  },
  beforeDestroy() {
    this.UiChartYaxisGroup && this.UiChartYaxisGroup.removeYaxis(this.options.id)
  }
}
</script>
